package thread;

import java.util.concurrent.CountDownLatch;

/**
 * @Description: 作用描述
 * @Author: hmm
 * @CreateDate: 2019/7/30$ 23:17$
 * @UpdateUser: hmm
 * @UpdateDate: 2019/7/30$ 23:17$
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
public class Demo3 {
    public static void excute() {
        CountDownLatch countDownLatch = new CountDownLatch(3);
        Thread A = new Thread(new Runnable() {
            @Override
            public void run() {
                printNum();
                countDownLatch.countDown();
            }
        });
        Thread B = new Thread(new Runnable() {
            @Override
            public void run() {
                printNum();
                countDownLatch.countDown();
            }
        });
        Thread C = new Thread(new Runnable() {
            @Override
            public void run() {
                printNum();
                countDownLatch.countDown();
            }
        });
        Thread D = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    countDownLatch.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                printNum();
            }
        });
        A.start();
        B.start();
        C.start();
        D.start();
    }

    private static void printNum() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName() + "--------" + i);
        }
    }

    public static void main(String[] args) {
        Demo3.excute();
    }
}
